<template>
	<view>
		这是商品列表页面,传过来的参数 {{categoryId}}
		<uni-list>
			<uni-list-item :clickable="true" @click="onClickItem(item.id)" v-for="(item,i) in goodsList " :key="i"
				:title="item.name" :note="item.spec" :thumb="item.img" thumb-size="lg">
			</uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				categoryId: null,
				goodsList: [],
			}
		},
		onLoad(options) {
			this.categoryId = parseInt(options.categoryId) || 0
			if (this.categoryId) {
				this.loadData()
			}
		},
		methods: {
			loadData() {
				//加载中提示
				uni.showLoading({
					title: 'loading'
				});
				// 调用接口
				let params = {
					categoryId: this.categoryId,
					pageNum: 1,
					pageSize: 8,
				}
				uni.request({
					url: 'http://localhost:5050/goods/list',
					data: params,
				}).then(result => {
					//加载提示消失
					uni.hideLoading();
					//控制台输出
					console.log(result.data);
					// 保存接口返回数据
					this.goodsList = result.data.data.list;
				}).catch(error => { //错误处理
					console.log(error)
				})
			},

			onClickItem(id) {
				uni.navigateTo({
					url: '/pages/goodsDetail/goodsDetail?goodsId=' + id
				})
			}
		}
	}
</script>

<style>

</style>